#!/bin/sh
# Copyright(c) 2011 OpenDomo Services SL. Licensed under GPL v3 or later

SERVICES=`ls /etc/inetd.d/* | wc -l`
PIDFILE="/var/run/inetd.pid"
case "$1" in
	"restart")
		$0 stop
		echo
		$0 start
		echo
	;;
	"reload")
		echo -n "Restarting $SERVICES TCP services..."
		cat /etc/inetd.d/* > /etc/inetd.conf
		kill -HUP `cat /var/run/inetd.pid`
	;;
	"start")
		echo -n "Starting $SERVICES TCP services..."
		cat /etc/inetd.d/* > /etc/inetd.conf
		/usr/sbin/inetd || exit 1
		ps -ef | grep "/usr/sbin/inetd" | grep -v grep | cut -b1-5 >$PIDFILE
		/usr/bin/logger -p notice "$SERVICES services started in inetd"
	;;
	"stop")
		echo -n "Killing inetd ... "
		kill -9 `cat /var/run/inetd.pid`
	;;
	"status")
		if test -f "$PIDFILE"; then
			echo "service running"
		else
			echo "service disabled"
			exit 1
		fi
	;;
esac
exit 0 
